package cn.newzai.util

import java.io.{FileNotFoundException, PrintWriter}

/**
 * Created with IntelliJ IDEA.
 * User: chenxiaohong
 * Date: 13-6-5
 * Time: 下午5:01
 * To change this template use File | Settings | File Templates.
 */
object WriteFile {

  def write( file :String, data :String) = {
    try
    {
      val print = new PrintWriter(file)
      try{
        if( file.endsWith(".h")
          || file.endsWith(".cpp")
          || file.endsWith(".cxx")
          || file.endsWith(".cs")
          || file.endsWith(".proto")){
          print.write("/*Code Generate by Scala ProtoGen, don't manual modify it.*/")
        }
        print.write(data)
      }finally {
        print.close()
        true
      }
    }catch{
      case e : FileNotFoundException =>
        println(e.getMessage)
        false
    }
  }
}
